package com.mall.util;

import com.mall.enums.CodeNumEntity;
import com.mall.pojo.ResponseMessage;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 更据ResponseMessage的信息返回工具类
 */
public class ResponseUtil {


    /**
     * @description: 是撒旦法
     */
    public static ResponseMessage success() {
        return new ResponseMessage(CodeNumEntity.SUCCESS.getCode(), CodeNumEntity.SUCCESS.getMessage());
    }

    /**
     * @description:提供状态信息的成功返回工
     */
    public static ResponseMessage success(String statusMessage) {
        return new ResponseMessage(CodeNumEntity.SUCCESS.getCode(), statusMessage);
    }

    /**
     * @description:失败后返回的Message
     *
     */
    public static ResponseMessage fail() {
        return new ResponseMessage(CodeNumEntity.FAIL.getCode(), CodeNumEntity.FAIL.getMessage());
    }

    public static ResponseMessage fail(String statusMessage) {
        return new ResponseMessage(CodeNumEntity.FAIL.getCode(), statusMessage);
    }

    /**
     * @description:数据库操作失败的Message
     *
     */
    public static ResponseMessage databaseError() {
        return new ResponseMessage(CodeNumEntity.DATABASE_ERROR.getCode(), CodeNumEntity.DATABASE_ERROR.getMessage());
    }

    public static ResponseMessage userError() {
        return new ResponseMessage(CodeNumEntity.USER_ERROR.getCode(), CodeNumEntity.USER_ERROR.getMessage());
    }

    public static ResponseMessage serverError() {
        return new ResponseMessage(CodeNumEntity.SERVER_ERROR.getCode(), CodeNumEntity.SERVER_ERROR.getMessage());
    }

    public static ResponseMessage customResponse(String statusCode, String statusMessage) {
        return new ResponseMessage(statusCode, statusMessage);
    }

    /**
     * @description:请求成功后带数据返回的Message
     * @param content:所需要返回的数据，
     *
     */
    public static ResponseMessage successWithData(Map<String, Object> content) {
        ResponseMessage responseMessage = success();
        responseMessage.setContent(content);
        return responseMessage;
    }

    /**
     * @description: 请求失败后带数据返回的Message
     * @param content:所需要返回的数据，
     *
     */
    public static ResponseMessage failWithData(Map<String, Object> content) {
        ResponseMessage responseMessage = fail();
        responseMessage.setContent(content);
        return responseMessage;
    }

    public static ResponseMessage customResponseWithData(String statusCode, String statusMessage, Map<String, Object> content) {
        ResponseMessage responseMessage = customResponse(statusCode, statusMessage);
        responseMessage.setContent(content);
        return responseMessage;
    }
}
